var erporderAllotPageVm = new Vue({
    el: '#erporderAllotPage',
    data: {
        erporderAllotPageVisible: false,
        showdeleteButton: '',
        orderInfo: {},
        erpOrder: {},
        csIdList: [],
        orderTaxList: [],
        pmcIdList: [],
        remarkList: [],
        userPaymentList: [],
        erpOrderItemEntityList: [],
        erpOrderProductionList: [],
        //商品类型的枚举!
        e:{
            goodsTypeEnum: [],
            taxTypeEnum: [],
        },
    },
    methods: {
        getInfo: function(orderNo){
            $.get(baseURL + "order/erporder/allotInfo/" + orderNo, function(r){
                erporderAllotPageVm.orderInfo = r.orderInfo;
                var orderTax = r.orderTax;
                if (orderTax != null){
                    erporderAllotPageVm.orderTaxList = [];
                    erporderAllotPageVm.orderTaxList.push(orderTax);
                }
                erporderAllotPageVm.erpOrder = r.erpOrder;
                erporderAllotPageVm.csIdList = r.csIdList;
                erporderAllotPageVm.pmcIdList = r.pmcIdList;
                erporderAllotPageVm.remarkList = r.remarkList;
                erporderAllotPageVm.userPaymentList = r.userPaymentList;
                erporderAllotPageVm.erpOrderItemEntityList = r.erpOrderItemEntityList;
                erporderAllotPageVm.erpOrderProductionList = r.erpOrderProductionList;
                erporderAllotPageVm.e.goodsTypeEnum = r.goodsTypeEnum;
                erporderAllotPageVm.e.taxTypeEnum = r.taxTypeEnum;
                erporderAllotPageVm.showdeleteButton = window.vm.showdeleteButton;
                erporderAllotPageVm.erporderAllotPageVisible = true;
            });
        },
        formatTaxType(row, column, cellValue){
            for (var i=0;i<erporderAllotPageVm.e.taxTypeEnum.length;i++){
                if(cellValue ==erporderAllotPageVm.e.taxTypeEnum[i].value){
                    return erporderAllotPageVm.e.taxTypeEnum[i].describe;
                }
            }
        },
        closeerporderAllotPage: function () {},
        delAllotItem: function (row) {
            this.$confirm('此操作将删除分配信息, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                callback: function (f) {
                    if (f == 'confirm'){
                        var productionId = row.productionId;
                        var orderNo = row.orderNo;
                        $.ajax({
                            type: "POST",
                            url: baseURL + "order/erporder/deleteAllotItem?productionId=" + productionId + "&orderId=" + orderNo,
                            contentType: "application/json",
                            success: function(r){
                                if(r.code == 0){
                                    erporderAllotPageVm.getInfo(erporderAllotPageVm.orderInfo.orderId);
                                }else{
                                    alert(r.msg);
                                }
                            }
                        });
                    }
                }
            })
        },
        /* 商品详情（报价计算过程） */
        showItemDetail: function (item) {
            window.itemQuoteDetailVm.loadData({
                itemId: item.originalItemId,
                goodsType: item.addcartBuyType,
                name: item.name
            })
        },
        /* 格式化报价商品属性显示 */
        formatAddon(row, column, cellValue, index){
            var addcartBuyType = row.addcartBuyType;
            if (addcartBuyType == 'print' || addcartBuyType == 'fast'){
                try {
                    if (typeof JSON.parse(cellValue) == "object"){
                        var jsonObj = JSON.parse(cellValue);
                        var content = '';
                        for (var a in jsonObj){
                            var partsName = jsonObj[a].partsName;
                            var text = partsName + '：';
                            var basicParam = jsonObj[a].basicParam;
                            if (!isBlank(basicParam)){
                                for (var b in basicParam){
                                    text += ' ' + basicParam[b];
                                }
                            }
                            var craftParam = jsonObj[a].craftParam;
                            if (!isBlank(craftParam)){
                                for (var c in craftParam){
                                    text += ' ' + craftParam[c];
                                }
                            }
                            if (a == jsonObj.length - 1){
                                content += text
                            }else {
                                content += text + '，'
                            }
                        }
                        return content;
                    }
                }catch (e){}
            }
            return cellValue;
        },
        /* 报价商品数量从addon中获取 */
        formatNum(row, column, cellValue, index){
            var nums = row.nums;
            var addcartBuyType = row.addcartBuyType;
            if (addcartBuyType == 'print' || addcartBuyType == 'fast'){
                try {
                    if (typeof JSON.parse(row.addon) == "object"){
                        var jsonObj = JSON.parse(row.addon);
                        for (var a in jsonObj){
                            var basicParam = jsonObj[a].basicParam;
                            if (!isBlank(basicParam)){
                                for (var b in basicParam){
                                    if (b == '数量'){
                                        nums = basicParam[b]
                                        break
                                    }
                                }
                            }
                        }
                    }
                }catch (e){}
            }
            return nums;
        }
    },
});